<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>白菜价</title>
    <link rel="stylesheet" href="./../css/baicaijia.css">
    <link rel="stylesheet" href="./../css/tongyong.css">
    <script src="./../js/flexible.js"></script>
</head>
<body>
        <div id="header">
            <a href="./index.html">
                <h1> &lt; </h1>
            </a>
            <h1>国内折扣</h1>
            <a href="#"><img src="./../assets/images/header_app.png" alt=""></a>
        </div>

        <div id="navigation">
            <!-- <span>全部</span>
            <span>热销</span>
            <span>9块邮</span>
            <span>19块邮</span>
            <span>数码家电</span>
            <span>居家</span>
            <span>居家</span>
            <span>热销</span>
            <span>热销</span>
            <span>热销</span>
            <span>热销</span>
            <span>热销</span> -->
            </div>

        <div id="text">
            <div class="box">
                <!-- <div class="left"><img src="http://seller.manmanbuy.com/ProPic/2016100009230957088.jpg" alt="" width="130px" height="130px"></div>
                <div class="right">
                    <p>[包邮]双十一红包 今日开启</p>
                    <p>
                        <span>￥0.0</span>
                        <del>￥0 1888</del>
                    </p>
                    <div class="bar clearfix"><a href="http://shop.m.taobao.com/shop/coupon.htm?activityId=27a14c9fc6bb4a48b917d567fcf8f664&amp;sellerId=2246833798" class="goquan" target="_blank"></a>
                        <i>
                        <em style="width:1%;"></em>
                        <span>1%</span>
                        </i>
                        <b>已领82张</b>
                    </div>
                    <p>
                        <span><a href="http://shop.m.taobao.com/shop/coupon.htm?activityId=27a14c9fc6bb4a48b917d567fcf8f664&amp;sellerId=2246833798" target="_blank">点此领15元优惠券</a></span>
                        <span><a biz-itemid="56297410_8818824_54778388" isconvert="1" href="http://s.click.taobao.com/3HlIdQx" target="_blank">下单链接</a></span>
                    
                </p> -->
                </div>
            </div>
        </div>

        <div id="footer">
            <ul>
                <li><a href="">登陆</a></li>
                <li><a href="">注册</a></li>
                <li><a href="javascript:void(0)" id="goTop">返回顶部</a></li>
            </ul>
            <div class="footer-bottom">
                <div>
                    <a href="">手机APP下载</a>
                    <span>慢慢买手机版</span>
                    <span>&nbsp;-&nbsp;掌上比价平台</span>
                    <p>m.manmanbuy.com</p>
                </div>
            </div>
        </div>
</body>
</html>
<script src="./../js/aajax.js"></script>

<script>
    let cc =document.querySelector("#text")
    let res;
    ajax({
            url: `http://chst.vip:1234/api/getbaicaijiaproduct?titleid=0`,
            success(res) {
                res = res.result;
                console.log(res);
                let html = "";
                res.forEach(item => {
                    html += `   
            <div class="box">
                <div class="left">${item.productImg}</div>
                <div class="right">
                    <p>${item.productName}</p>
                    <p><span>${item.productPrice}</span></p>
                    ${item.productCouponRemain}
                    <p>
                        <span>${item.productCoupon}</span>
                        <span>${item.productHref}</span>
                    </p>
                </div>
            </div> `
                })
                cc.innerHTML = html
                // console.log(cc)
            },
            error(err, xhr) {
                
            }
        })

        let nav = document.querySelector('#navigation')
        console.log(nav);
        nav.addEventListener('click',function (e) {
            //兼容处理
        var event = e || window.event;
        var target = event.target ;
        if (target.innerText == '全部') {
            target.onclick = function(){
                // console.log(222);
            }
        }

        console.log(target.className);
        

        ajax({
            url: `http://chst.vip:1234/api/getbaicaijiaproduct?titleid=${target.className}`,
            success(res) {
                // console.log(res);
                res = res.result;
                let html = "";
                res.forEach(item => {
                    html += `   
            <div class="box">
                <div class="left">${item.productImg}</div>
                <div class="right">
                    <p>${item.productName}</p>
                    <p><span>${item.productPrice}</span></p>
                    ${item.productCouponRemain}
                    <P>
                        <span>${item.productCoupon}</span>
                        <span>${item.productHref}</span>
                    </p>
                </div>
            </div> `
                })
                cc.innerHTML = html
                // console.log(cc)
            },
            error(err, xhr) {
                // console.log(err);
            }
        })
        })

        let uu;
    ajax({
        url: "http://chst.vip:1234/api/getbaicaijiatitle",
        success(uu) {
            
            uu = uu.result;
            console.log(uu,222);

            let header = "";
            
            uu.forEach((item,index) => {
                header += ` 
                <span class="${item.titleId}">${item.title}</span>
                 `
            })
            
            nav.innerHTML = header
            
        },
        error(err, xhr) {
            console.log(err);
        }
    })


    let goTop = document.getElementById('goTop')
    goTop.onclick = function () {
        document.documentElement.scrollTop = 0
    }




</script>